package com.atguigu.gulimall.order.vo;

import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Data
public class ConfirmVo {

    /**
     * 收货地址
     */
    private List<MemberAddressVo> address;

    /**
     * 商品信息
     */
    private List<OrderItemVo> items;

    /** 优惠券（会员积分） **/
    private Integer integration;

    /**
     * 是否有库存
     */

    Map<Long,Boolean> stocks;

    /**
     * 防重令牌
     */
    String OrderToken;

    public Integer getCount() {
        Integer count=0;
        if (!CollectionUtils.isEmpty(items)){
            for (OrderItemVo item:items) {
                count +=item.getCount();
            }
        }
        return count;
    }

    public BigDecimal getTotal() {
        BigDecimal countPrice=new BigDecimal("0");
        if (!CollectionUtils.isEmpty(items)){
            for (OrderItemVo item:items) {
                BigDecimal itemPrice=item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                countPrice =countPrice.add(itemPrice);
            }
        }
        return countPrice;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

}
